unit uFrmLocPersonFilter;

interface

uses
  SysUtils, Classes, Variants, Windows, Messages, Graphics, Controls, Forms,
  Dialogs, StdCtrls, uCxtTypes, uCxtPackage, uCxtForm, uFrmCity, ExtCtrls;

type
  TFrmLocPersonFilter = class(TBaseForm)
    Panel1: TPanel;
    Label3: TLabel;
    lblCheXing: TLabel;
    Label1: TLabel;
    Label7: TLabel;
    cbbSex: TComboBox;
    edtName: TEdit;
    edtPhone: TEdit;
    btnDQCSSel: TButton;
    btnClearDQWZ: TButton;
    edtCityCode: TEdit;
    btnOK: TButton;
    btnCancel: TButton;
    procedure btnDQCSSelClick(Sender: TObject);
    procedure btnClearDQWZClick(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
  private
    fCityCodes: string;
    fFilter: TLocPersonFilter;
    procedure SetFilter(const Value: TLocPersonFilter);
  public
    property Filter: TLocPersonFilter read fFilter write SetFilter;
  end;

function QueryLocPersonFilter(filter: TLocPersonFilter): Boolean;

implementation

{$r *.dfm}

var
  FrmLocPersonFilter: TFrmLocPersonFilter;

function QueryLocPersonFilter(filter: TLocPersonFilter): Boolean;
begin
  if not Assigned(FrmLocPersonFilter) then
    FrmLocPersonFilter := TFrmLocPersonFilter.Create(Application);
  FrmLocPersonFilter.Filter := filter;
  Result := FrmLocPersonFilter.ShowModal = mrOk;
end;
  
{ TFrmLocPersonFilter }

procedure TFrmLocPersonFilter.btnClearDQWZClick(Sender: TObject);
begin
  edtCityCode.Text := '';
  fCityCodes := '';
end;

procedure TFrmLocPersonFilter.btnDQCSSelClick(Sender: TObject);
var
  names, codes: string;
begin
  if PromptCities(edtCityCode.Text, names, codes, [asoAllowCity]) then
  begin
    edtCityCode.Text := names;
    fCityCodes := codes;
  end;  
end;

procedure TFrmLocPersonFilter.btnOKClick(Sender: TObject);
begin
  fFilter.PersonName := edtName.Text;
  fFilter.Phone := edtPhone.Text;
  fFilter.Sex := cbbSex.Text;
  fFilter.CityNames := edtCityCode.Text;
  fFilter.CityCodes := fCityCodes;
  ModalResult := mrOk;
end;

procedure TFrmLocPersonFilter.SetFilter(const Value: TLocPersonFilter);
begin
  fFilter := Value;
  edtName.Text := fFilter.PersonName;
  edtPhone.Text := fFilter.Phone;
  cbbSex.ItemIndex := cbbSex.Items.IndexOf(fFilter.Sex);
  edtCityCode.Text := fFilter.CityNames;
  fCityCodes := fFilter.CityCodes;
end;

end.
